//
//  SellerServiceGuardViewController.m
//  nonghubao
//
//  Created by 王 文彬 on 13-8-18.
//  Copyright (c) 2013年 Chongqing Nonghubao Co., Ltd. All rights reserved.
//

#import "SellerServiceGuardViewController.h"
#import "Helper.h"
#import "SellerServiceOpeningViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "SellerServiceDemotionViewController.h"

@interface SellerServiceGuardViewController ()

@end

@implementation SellerServiceGuardViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithSeller:(NSDictionary *)seller
{
    self = [super init];
    if (self) {
        _seller = seller;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //背景
    self.view.backgroundColor = _SYS_COLOR_BACKGROUND;
    
    self.title = _L(@"vc_title_050");
    
    //导航栏左按钮：返回
    UIButton* backButton = [Helper buttonWithStyle:ButtonStyleNavigationReturn];
    [backButton addTarget:self action:@selector(backButtonEvent) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    if ([_seller[@"sellerType"] intValue] == 1) {
        
        [self.view addSubview:[self makeNormalSellerView]];
    }
    else {
        
        [self.view addSubview:[self makeTipView]];
    }
    
    [self.view addSubview:[self makeVipSellerView]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)backButtonEvent
{
    [self.navigationController popViewControllerAnimated:true];
}

- (UIView *)makeTipView
{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, _SYS_FRAME_WIDTH - 20, 110)];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.borderWidth = 1;
    view.layer.borderColor = [_SYS_COLOR_003 CGColor];
    view.layer.cornerRadius = 3;
    
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(view.frame.size.width / 2 - 20, 20, 40, 40)];
    imageView.image = [UIImage imageNamed:@"com_icon_017"];
    [view addSubview:imageView];
    
    UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 60, view.frame.size.width, 25)];
    textView.text = _L(@"title_23");
    textView.font = _SYS_FONT_005;
    textView.textColor = _SYS_COLOR_007;
    textView.scrollEnabled = false;
    textView.editable = false;
    textView.textAlignment = UITextAlignmentCenter;
    [view addSubview:textView];
    
    UIButton *demoteButton = [[UIButton alloc] initWithFrame:CGRectMake(120.0f, Y_AND_HEIGHT(textView.frame)+5.0f, 60.0f, 15.0f)];
    [demoteButton setTitle:_L(@"btn_yes_45") forState:UIControlStateNormal];
    [demoteButton setBackgroundColor:[UIColor whiteColor]];
    demoteButton.titleLabel.font = _SYS_FONT_002;
    [demoteButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [demoteButton addTarget:self action:@selector(demoteButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:demoteButton];
    
    return view;
}

- (UIView *)makeNormalSellerView
{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, _SYS_FRAME_WIDTH - 20, 110)];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.borderWidth = 1;
    view.layer.borderColor = [_SYS_COLOR_003 CGColor];
    view.layer.cornerRadius = 3;
    
    UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, view.frame.size.width, 40)];
    textView.text = _L(@"title_87");
    textView.font = _SYS_FONT_004;
    textView.textColor = _SYS_COLOR_006;
    textView.scrollEnabled = false;
    textView.editable = false;
    [view addSubview:textView];

    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(10, 60, view.frame.size.width - 20, 40)];
    [button addTarget:self action:@selector(upgradeVipButtonEvent) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:_L(@"btn_yes_35") forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"com_btn_006_n"] forState:UIControlStateNormal];
    [view addSubview:button];
    
    return view;
}

- (UIView *)makeVipSellerView
{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(10, 125, _SYS_FRAME_WIDTH - 20, 110)];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.borderWidth = 1;
    view.layer.borderColor = [_SYS_COLOR_003 CGColor];
    view.layer.cornerRadius = 3;
    
    UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, view.frame.size.width, 40)];
    textView.text = [NSString stringWithFormat:_L(@"title_88"), _seller[@"sellerExpiredTime"]];
    textView.font = _SYS_FONT_004;
    textView.textColor = _SYS_COLOR_006;
    textView.scrollEnabled = false;
    textView.editable = false;
    textView.textAlignment = UITextAlignmentCenter;
    [view addSubview:textView];
    
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(10, 60, view.frame.size.width - 20, 40)];
    [button addTarget:self action:@selector(renewButtonEvent) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:_L(@"btn_yes_36") forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"com_btn_008_n"] forState:UIControlStateNormal];
    [view addSubview:button];
    
    return view;
}

- (void)upgradeVipButtonEvent
{
    SellerServiceOpeningViewController* sellerServiceOpeningViewController = [[SellerServiceOpeningViewController alloc] initWithType:3];
    sellerServiceOpeningViewController.hidesBottomBarWhenPushed = true;
    [self.navigationController pushViewController:sellerServiceOpeningViewController animated:true];
}

- (void)renewButtonEvent
{
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"当前功能尚未开通，请等待" message:nil delegate:nil cancelButtonTitle:_L(@"btn_yes_01") otherButtonTitles: nil];
    [alertView show];
}

- (void)demoteButtonEvent:(id)sender
{
    SellerServiceDemotionViewController *sellerServiceDemotionVC = [[SellerServiceDemotionViewController alloc] init];
//    UINavigationController *sellerServiceDemotionNC = [[UINavigationController alloc] initWithRootViewController:sellerServiceDemotionVC];
//    [Helper navigationControllerCommonStyle:sellerServiceDemotionNC];
//    [self.navigationController presentModalViewController:sellerServiceDemotionNC animated:YES];
    [self.navigationController pushViewController:sellerServiceDemotionVC animated:YES];
}

@end
